<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of settings
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Settings extends CI_Controller {

    //put your code here


    function settings() {
        parent :: __construct();
        $this->commoncall->check_admin_login();
    }

    function index() {
        $data['settings'] = $this->settings_model->settings_detail();
        $this->load->view('admin/admin_settings', $data);
    }
    function get_setting() {
        $data['settings'] = $this->settings_model->settings_detail();
        if ($this->input->post('get_value')) {
            $this->form_validation->set_rules('setting_variable', 'setting_variable', 'required|xss_clean');
            $name = $this->input->post('setting_variable');
            if ($this->form_validation->run()) {
                $this->db->select('*')->from('web_settings')->where('variable', $name);
                $query = $this->db->get();
                $result = $query->result();
                $row = $query->row();
                $data['setting_id'] = $row->id;
                $data['setting_description'] = $row->description;
                $data['setting_variable'] = $row->variable;
                $data['setting_value'] = $row->value;
                $data['setting_auto'] = $row->auto;
            } else {
                $this->session->set_flashdata('message', 'Choose Settings type');
                redirect('admin/settings', $data);
            }
        }

        $this->load->view('admin/admin_settings', $data);
    }
    function update() {

        if ($this->input->post('setting_update')) {
            $this->form_validation->set_rules('variable_value', 'variable_value', 'required|xss_clean');
            $this->form_validation->set_rules('setting_variable', 'setting_variable', 'required|xss_clean');
            $this->form_validation->set_rules('setting_id', 'setting_id', 'required|xss_clean');
            $id = trim($this->input->post('setting_id'));
            $setting_value = trim($this->input->post('variable_value'));

            if ($this->form_validation->run()) {
                $data = array('value' => $setting_value);
                $this->db->where('id', $id);
                $this->db->update('web_settings', $data);
            }
        }
       
        redirect('admin/settings');
    }
}
?>